<html>
<head><meta charset="utf-8"><title>In what case these impls conflict? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html">In what case these impls conflict?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="164223385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164223385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164223385">(Apr 26 2019 at 00:53)</a>:</h4>
<p>For this code <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=e584d0a9cc905d31aed9abcc3a23b8fa" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=e584d0a9cc905d31aed9abcc3a23b8fa">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=e584d0a9cc905d31aed9abcc3a23b8fa</a> we report conflicting impls, however I have failed to think of a case where this would actually be a conflicting implementation.</p>



<a name="164223568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164223568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164223568">(Apr 26 2019 at 00:57)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> those impls cannot overlap but <code>rustc</code> is too dumb to take into account that associated types are functions in terms of coherence</p>



<a name="164223640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164223640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164223640">(Apr 26 2019 at 00:58)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span>  simplified: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=3da3b94fd735979884440d4f3ca9fbf8" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=3da3b94fd735979884440d4f3ca9fbf8">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=3da3b94fd735979884440d4f3ca9fbf8</a></p>



<a name="164223756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164223756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164223756">(Apr 26 2019 at 01:00)</a>:</h4>
<p>That simplification looks alpha-equivalent to me <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="164223795"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164223795" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164223795">(Apr 26 2019 at 01:01)</a>:</h4>
<p>is making rust to understand this something we want to do?</p>



<a name="164223843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164223843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164223843">(Apr 26 2019 at 01:02)</a>:</h4>
<p><a href="https://github.com/rust-lang/rfcs/pull/1672" target="_blank" title="https://github.com/rust-lang/rfcs/pull/1672">https://github.com/rust-lang/rfcs/pull/1672</a> (postponed)</p>



<a name="164223898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164223898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164223898">(Apr 26 2019 at 01:04)</a>:</h4>
<p>Aww.</p>



<a name="164223948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164223948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164223948">(Apr 26 2019 at 01:04)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> do you remember what GHC does?</p>



<a name="164223958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164223958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164223958">(Apr 26 2019 at 01:04)</a>:</h4>
<p>I do not. I never hit this back when I was using Haskell at least.</p>



<a name="164224341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164224341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164224341">(Apr 26 2019 at 01:13)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="cm">{-# LANGUAGE TypeFamilies, FlexibleInstances #-}</span>
<span class="cm">{-# LANGUAGE UndecidableInstances #-}</span> <span class="c1">-- oh noes!</span>

<span class="kr">class</span> <span class="kt">X</span> <span class="n">a</span> <span class="kr">where</span> <span class="kr">type</span> <span class="kt">F</span> <span class="n">a</span> <span class="ow">::</span> <span class="o">*</span>
<span class="kr">class</span> <span class="kt">X</span> <span class="n">a</span> <span class="ow">=&gt;</span> <span class="kt">Y</span> <span class="n">a</span> <span class="kr">where</span>
<span class="kr">data</span> <span class="kt">A</span> <span class="ow">=</span> <span class="kt">A</span>
<span class="kr">data</span> <span class="kt">B</span> <span class="ow">=</span> <span class="kt">B</span>
<span class="kr">instance</span> <span class="p">(</span><span class="kt">X</span> <span class="n">i</span><span class="p">,</span> <span class="kt">A</span> <span class="o">~</span> <span class="kt">F</span> <span class="n">i</span><span class="p">)</span> <span class="ow">=&gt;</span> <span class="kt">Y</span> <span class="n">i</span> <span class="kr">where</span>
<span class="kr">instance</span> <span class="p">(</span><span class="kt">X</span> <span class="n">i</span><span class="p">,</span> <span class="kt">B</span> <span class="o">~</span> <span class="kt">F</span> <span class="n">i</span><span class="p">)</span> <span class="ow">=&gt;</span> <span class="kt">Y</span> <span class="n">i</span> <span class="kr">where</span>
</pre></div>


<p><span class="user-mention" data-user-id="123586">@nagisa</span> GHC 8.0.2 accepts this ^---</p>



<a name="164224424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164224424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164224424">(Apr 26 2019 at 01:15)</a>:</h4>
<p>tho I should check with a newer version to make sure it still holds</p>



<a name="164224640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164224640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164224640">(Apr 26 2019 at 01:20)</a>:</h4>
<p>Explanatory notes for those who are not Haskell proficient:<br>
1. <code>class</code> ==&gt; <code>trait</code>;<br>
2. the <code>Self</code> type is the first type variable in the <code>class</code>.<br>
3. <code>type F a :: *</code> denotes an associated type <code>F</code> that when given type <code>a</code> projects to a type of kind <code>*</code> (concrete types)<br>
4. <code>X a =&gt; Y a</code> denotes a super class constraint (to implement <code>Y</code> for <code>a</code> you must also implement <code>X</code> for <code>a</code>)<br>
5. <code>data A = A</code> is the same as <code>struct A;</code><br>
6. <code>instance Ctx =&gt; Class Type</code> denotes that you are defining an implementation of <code>Class</code> for <code>Type</code> provided that <code>Ctx</code> holds.<br>
7. <code>Alpha ~ Beta</code> is a type equality constraint</p>



<a name="164224714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/In%20what%20case%20these%20impls%20conflict%3F/near/164224714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/In.20what.20case.20these.20impls.20conflict.3F.html#164224714">(Apr 26 2019 at 01:22)</a>:</h4>
<p>8. Type variables in Haskell are lowerCamelCased, concrete types are UpperCamelCased; Haskell implicitly quantifies type variables by default</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>